package com.quanxiaoha.weblog.web.controller;

import com.quanxiaoha.weblog.common.aspect.ApiOperationLog;
import com.quanxiaoha.weblog.common.utils.Response;
import com.quanxiaoha.weblog.web.model.vo.favorite.AddFavoriteReqVO;
import com.quanxiaoha.weblog.web.model.vo.favorite.FindFavoriteListReqVO;
import com.quanxiaoha.weblog.web.model.vo.favorite.RemoveFavoriteReqVO;
import com.quanxiaoha.weblog.web.service.FavoriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 收藏控制器
 */
@RestController
@RequestMapping("/favorite")
@Api(tags = "收藏")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @PostMapping("/add")
    @ApiOperation(value = "添加收藏")
    @ApiOperationLog(description = "添加收藏")
    public Response<?> addFavorite(@RequestBody AddFavoriteReqVO addFavoriteReqVO) {
        return favoriteService.addFavorite(addFavoriteReqVO);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "取消收藏")
    @ApiOperationLog(description = "取消收藏")
    public Response<?> removeFavorite(@RequestBody RemoveFavoriteReqVO removeFavoriteReqVO) {
        return favoriteService.removeFavorite(removeFavoriteReqVO);
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取收藏列表")
    @ApiOperationLog(description = "获取收藏列表")
    public Response<?> findFavoriteList(@RequestBody FindFavoriteListReqVO findFavoriteListReqVO) {
        return favoriteService.findFavoriteList(findFavoriteListReqVO);
    }

    @GetMapping("/status")
    @ApiOperation(value = "检查收藏状态")
    @ApiOperationLog(description = "检查收藏状态")
    public Response<?> checkFavoriteStatus(@RequestParam Long articleId, 
                                         @RequestParam(required = false) String sessionId,
                                         @RequestParam Integer type) {
        return favoriteService.checkFavoriteStatus(articleId, sessionId, type);
    }
}
